﻿/* 5. Write a program that finds the maximal increasing sequence in an array. 
 * Example: {3, 2, 3, 4, 2, 2, 4} -> {2, 3, 4} */

using System;

public class MaximalIncreasingSequence
{
    public static void Main()
    {
        ulong arrayLength;
        double[] array;
        ulong firstMaxSequence;
        ulong firstIndexInFirstMaxSequence;
        ulong currentMaxSequence = 0;
        ulong pointer;
        ulong counter;

        Console.Write("\nThe length of array: ");
        arrayLength = ulong.Parse(Console.ReadLine());
        Console.WriteLine();

        if (0 < arrayLength)
        {
            array = new double[arrayLength];

            for (ulong i = 0; i < arrayLength; i++)
            {
                Console.Write("Array[{0}]= ", i);
                array[i] = double.Parse(Console.ReadLine());
            }

            firstMaxSequence = 1;
            firstIndexInFirstMaxSequence = 0;
            pointer = 0;

            while (pointer < arrayLength - 1)
            {
                currentMaxSequence = 1;
                counter = pointer + 1;

                while (counter < arrayLength)
                {
                    if (array[pointer] < array[counter])
                    {
                        currentMaxSequence++;
                        pointer++;
                        counter++;
                    }
                    else
                        break;
                }

                if (currentMaxSequence > firstMaxSequence)
                {
                    firstMaxSequence = currentMaxSequence;
                    firstIndexInFirstMaxSequence = pointer + 1 - currentMaxSequence;
                }

                pointer++;
            }

            Console.Write("\nThe first maximal increasing sequence in this array is\n {0} ", "{");
            for (ulong i = firstIndexInFirstMaxSequence; i < firstIndexInFirstMaxSequence + firstMaxSequence - 1; i++)
                Console.Write("{0}, ", array[i]);

            Console.WriteLine("{0} {1}\n", array[firstIndexInFirstMaxSequence + firstMaxSequence - 1], "}");
        }
        else
            Console.WriteLine("The length of array must be natural!\n");
    }
}